package com.example.yuejianapp14.Activity.Activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.yuejianapp14.Activity.JavaBean.Club;
import com.example.yuejianapp14.Activity.JavaBean.Success;
import com.example.yuejianapp14.Activity.JavaBean.class1;
import com.example.yuejianapp14.Activity.Listener.ClassInfoListener;
import com.example.yuejianapp14.Activity.Listener.ClassListener;
import com.example.yuejianapp14.Activity.Listener.ClubNoListListener;
import com.example.yuejianapp14.Activity.Listener.EnterListener;
import com.example.yuejianapp14.Activity.Listener.ListListener;
import com.example.yuejianapp14.Activity.Model.ClassModel;
import com.example.yuejianapp14.Activity.Model.ClubModel;
import com.example.yuejianapp14.Activity.Model.CoachModel;
import com.example.yuejianapp14.Activity.Model.EnterModel;
import com.example.yuejianapp14.R;
import com.squareup.picasso.Picasso;

import java.util.List;

import static android.R.attr.phoneNumber;

public class ClassActivity extends AppCompatActivity {
    private ImageView class_pic;
    private TextView class_info,classaddress,classtime,classcost;
    private Context mContext;
    private String class_id;
    private Button callbtn,enterbtn;
    private SharedPreferences sp;
    String etype;
    String etypeid;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_class);
        getData();
        initViews();
        callbtn();
        enterbtn();
        Intent intent=getIntent();

        intent.getStringExtra("classid");
        etypeid= intent.getStringExtra("classid");
        Picasso.with(mContext).load("http://10.0.2.2/YueJian/Public/photo/class/"+getIntent().getStringExtra("img")).into(class_pic);


    }


    public void initViews(){
        class_info = (TextView) findViewById(R.id.class_info);
        classcost = (TextView) findViewById(R.id.classcost);
        classaddress = (TextView) findViewById(R.id.classaddress);
        classtime = (TextView) findViewById(R.id.classtime);
        class_pic=(ImageView)findViewById(R.id.class_pic);
        callbtn = (Button) findViewById(R.id.classphone);
        enterbtn = (Button) findViewById(R.id.classenter);
        sp=getSharedPreferences("uid",MODE_PRIVATE);
    }

    ClassInfoListener classInfoListener =new ClassInfoListener() {
        @Override
        public void onResponse(class1 a) {
            class_info.setText(a.getClassinfo());
            classcost.setText("¥"+a.getClasscost());
            classaddress.setText(a.getClassaddress());
            classtime.setText(a.getClasstime());
        }

        @Override
        public void onFail(String msg) {

        }
    };

    private void getData() {
        Intent intent = getIntent();
        ClassModel classModel =new ClassModel();
        classModel.classinfo(intent.getStringExtra("classid"),classInfoListener);
    }

    private void callbtn(){
        callbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Toast.makeText(ClassActivity.this,"拨号中...", Toast.LENGTH_SHORT).show();
            }
        });

    }

    private void enterbtn(){
        enterbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EnterModel enterModel =new EnterModel();
                enterModel.enter(sp.getString("uid",""),"1",etypeid, EnterListener);
            }
        });

    }

    ListListener<Success> EnterListener =new ListListener<Success>() {
        @Override
        public void onResponse(Success a) {
            if (a.getSuccess().equals("1")) {
                Toast.makeText(ClassActivity.this, "报名成功", Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(ClassActivity.this, "报名失败", Toast.LENGTH_SHORT).show();

        }
    };











}
